package com.rd.student.jiaji.class3.zhangshixuan.Day0808;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Demo01 {
    public static void main(String[] args) throws Exception {
        //创建学生集合
        ArrayList<Student01> students = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入学生姓名：");
            String name = sc.nextLine();
            System.out.println("请输入语文成绩：");
            int chineseScore = sc.nextInt();
            System.out.println("请输入数学成绩：");
            int mathScore = sc.nextInt();
            Student01 s = new Student01();
            s.setName(name);
            s.setChineseScore(chineseScore);
            s.setMathScore(mathScore);
            s.setZhongfen(mathScore + chineseScore);
            students.add(s);
        }
        //创建Student.txt文件，将学生信息的标题导入
        File file = new File("Student.txt");
        BufferedWriter bw = new BufferedWriter(new FileWriter(file));
        bw.write("学生姓名 ");
        bw.write("语文成绩 ");
        bw.write("数学成绩 ");
        bw.write("总分 ");
        bw.newLine();

        for (Student01 s : students) {
            String name = s.getName();
            int chinese = s.getChineseScore();
            int math = s.getMathScore();
            int total = s.getZhongfen();
            //写入三个数据，计算总分
            bw.write(name + " ");
            bw.write(chinese + " ");
            bw.write(math + " ");
            bw.write(total + " ");
            bw.newLine();
        }
        bw.close();
    }
}

